package topiccontroller

import (
	"ginjt/JsonResult"
	"ginjt/model"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

func Topic(c *gin.Context)  {
	//c.String(http.StatusOK,"ID=%s",c.Param("topic_id"))
	sid := c.Param("topic_id")
	id,_:= strconv.Atoi(sid)
	r := JsonResult.Ok()
	r.PutData(model.NewTopic(id,sid+"这是title"))
	c.JSON(http.StatusOK,r.GetH())
}

func Topics(c *gin.Context)  {
	c.String(http.StatusOK,"ID=%s","获取所有topic")
}

func NewTopic(c *gin.Context)  {
	t := model.Topic{}
	err:=c.BindQuery(&t)
	r := JsonResult.Ok()
	if err != nil {
		r.PutData(err.Error())
	} else {
		r.PutData(t)
	}


	c.JSON(http.StatusOK,r.GetH())
}



func MTopics(c *gin.Context)  {
	t := model.Topics{}
	err:=c.BindJSON(&t)
	r := JsonResult.Ok()
	if err != nil {
		r.PutCode(http.StatusBadRequest).
			PutMsg("提交参数有误").
			PutData(err.Error())
	} else {
		r.PutData(t)
	}


	c.JSON(http.StatusOK,r.GetH())
}
